import 'package:just_audio/just_audio.dart';
import 'package:walker/player.dart' show MyAudioPlayer;

import 'types.dart';

class MyAudioPlayerJustAudio implements MyAudioPlayer {
  final player = AudioPlayer();

  @override
  MyPlayerState get state {
    if (player.playing) {
      return MyPlayerState.playing;
    } else if (player.processingState == ProcessingState.ready) {
      return MyPlayerState.paused;
    } else {
      return MyPlayerState.stopped;
    }
  }

  @override
  Future<void> initAssets(String url) async {
    // await player.setSource(AssetSource(url));
    player.setAsset(url);
    await pause();
  }

  @override
  Future<void> pause() {
    return player.pause();
  }

  @override
  Future<void> resume() {
    return player.play();
  }

  @override
  Future<void> stop() {
    return player.stop();
  }

  @override
  Future<void> seek(Duration position) {
    return player.seek(position);
  }

  @override
  Future<void> dispose() {
    return player.dispose();
  }
}
